package model;

import java.util.Date;

/**
 * 列车实体类
 */
public class Train {
    private int id;
    private String trainNumber;
    private String departure;
    private String destination;
    private Date departureTime;
    private Date arrivalTime;
    private int totalSeats;
    private int availableSeats;
    private double price;
    private String[] carriages = {"A", "B", "D", "E", "F"}; // 可用车厢
    private int[] carriageSeats; // 每个车厢的座位数

    public Train() {}

    public Train(String trainNumber, String departure, String destination,
                 Date departureTime, Date arrivalTime, int totalSeats, double price) {
        this.trainNumber = trainNumber;
        this.departure = departure;
        this.destination = destination;
        this.departureTime = departureTime;
        this.arrivalTime = arrivalTime;
        this.totalSeats = totalSeats;
        this.availableSeats = totalSeats;
        this.price = price;
        this.carriageSeats = new int[carriages.length];

        // 平均分配座位到各车厢
        int seatsPerCarriage = totalSeats / carriages.length;
        for (int i = 0; i < carriages.length; i++) {
            carriageSeats[i] = seatsPerCarriage;
        }
        // 处理余数
        int remainder = totalSeats % carriages.length;
        for (int i = 0; i < remainder; i++) {
            carriageSeats[i]++;
        }
    }

    public int getId() { return id; }
    public void setId(int id) { this.id = id; }

    public String getTrainNumber() { return trainNumber; }
    public void setTrainNumber(String trainNumber) { this.trainNumber = trainNumber; }

    public String getDeparture() { return departure; }
    public void setDeparture(String departure) { this.departure = departure; }

    public String getDestination() { return destination; }
    public void setDestination(String destination) { this.destination = destination; }

    public Date getDepartureTime() { return departureTime; }
    public void setDepartureTime(Date departureTime) { this.departureTime = departureTime; }

    public Date getArrivalTime() { return arrivalTime; }
    public void setArrivalTime(Date arrivalTime) { this.arrivalTime = arrivalTime; }

    public int getTotalSeats() { return totalSeats; }
    public void setTotalSeats(int totalSeats) { this.totalSeats = totalSeats; }

    public int getAvailableSeats() { return availableSeats; }
    public void setAvailableSeats(int availableSeats) { this.availableSeats = availableSeats; }

    public double getPrice() { return price; }
    public void setPrice(double price) { this.price = price; }

    public String[] getCarriages() { return carriages; }
    public int[] getCarriageSeats() { return carriageSeats; }
    public void setCarriageSeats(int[] carriageSeats) { this.carriageSeats = carriageSeats; }
}